"""
m = 0
for i in range(1,1000):

    a = "{:b}".format(i)
    for a1 in a:
        a1 = int(a1)
        a2 = 0
        a2 = a2 + a1
    b = '{:o}'.format(i)
    for b1 in b:
        b1 = int(b1)
        b2 = 0
        b2 = b2 + b1
    if a2 == b2:
        print(i)
        m = m + 1
        print(f"这是第{m}个")
        if m == 23:
            break
"""
"""
mylist = ("393353 901440 123481 850930 423154 240461 373746 232926 396677 486579 744860 468782 941389 777714 992588 "
          "343292 385198 876426 483857 241899 544851 647930 772403 109929 882745 372491 877710 340000 659788 658675 "
          "296521 491295 609764 718967 842000 670302")
mylist1 = mylist.split(" ")
mydict = {}
for i in range(1,36):
    num = mylist1[i]
    num = int(num)
    for b in range(1,300):
        n = 0
        n = num % b
        if n == 0:
            num1 = 0
            num1 = num1 + 1
    mydict[num] = num1
print(mydict)
"""
"""
q=[393353,901440,123481,850930,23154,240461,373746,232926,396677,486579,744860,468782,941389,777714,992588,343292,385198,876426,483857,241899,544851,647930,772403,109929,882745,372491,877710,340000,659788,65867,296521,491295,609764,718967,842000,670302]
list1 = [0]*len(q)
for i in q:
    a=q.index(i)
    s=0
    for m in range(1,i):
        if i%m==0:
            s+=1
    list1[a]=s
b=list1.index((max(list1)))
print(q[b])
"""
"""
mylist = []
num = input("请给一个十万位和万位上的数字均不为0的六位十进制数")
for i in num:
    mylist.append(i)
num1 = mylist[0]
mylist.append(num1)
del mylist[0]
ten = 5
fin_num = 0
for i in mylist:
    print(i)
    i = int(i)
    fin_num = 10 ** ten * i + fin_num
    print(fin_num)
    ten = ten - 1
print(fin_num)
"""
"""
my_word = input("输入一行包含一个字符串，仅由小写英文字符组成，字符串中至少包含一个元音字母")
for letter in my_word:
    if letter == "a" or letter == "e" or letter == "i" or letter == "o" or letter == "u":
        vowel = letter
    else:
        continue
print(vowel)
"""
"""
num = input("请输入有一个整数")
while 1 == 1:
    e_num = 1
    for letter in num:
        letter = int(letter)
        if letter != 0:
            e_num = letter * e_num
        else:
            continue
    if e_num < 10:
        break
    else:
        num = str(e_num)
        print(num)
print(e_num)
"""
"""
nk = input("先输入有几个数，再输入区间包含几个数（用空格分开）")
my_list = nk.split(" ")
n = int(my_list[0])
k = int(my_list[1])
a = input("包含 n 个整数，相邻的整数之间使用一个空格分隔，表示给定的序列")
my_list_num = a.split(" ")
fin_all = 0
for a in range(0,n-k):
    a = int(a)
    all = 0
    for num in range(a,a+k):
        num = int(num)
        b = my_list_num[num]
        b = int(b)
        all = all + b
    if all > fin_all:
        fin_all = all
print(fin_all)
"""

"""
问题描述
　　小蓝有一个01矩阵。他打算将第一行第一列的 0 变为 2 。变化过程有传染性，
    每次 2 的上下左右四个相邻的位置中的 0 都会变成 2 。直到最后每个 2 的周围都是 1 或 2 结束。
　　请问，最终矩阵中有多少个 2 ？
　　以下是小蓝的矩阵，共 30 行 40 列。
　　0000100010000001101010101001001100000011
　　0101111001111101110111100000101010011111
　　1000010000011101010110000000001011010100
　　0110101010110000000101100100000101001001
　　0000011010100000111111001101100010101001
　　0110000110000000110100000000010010100011
　　0100110010000110000000100010000101110000
　　0010011010100110001111001101100110100010
　　1111000111101000001110010001001011101101
　　0011110100011000000001101001101110100001
　　0000000101011000010011111001010011011100
　　0000100000011001000100101000111011101100
　　0010110000001000001010100011000010100011
　　0110110000100011011010011010001101011011
　　0000100100000001010000101100000000000010
　　0011001000001000000010011001100101000110
　　1110101000011000000100011001001100111010
　　0000100100111000001101001000001010010001
　　0100010010000110100001100000110111110101
　　1000001001100010011001111101011001110001
　　0000000010100101000000111100110010101101
　　0010110101001100000100000010000010110011
　　0000011101001001000111011000100111010100
　　0010001100100000011000101011000000010101
　　1001111010010110011010101110000000101110
　　0110011101000010100001000101001001100010
　　1101000000010010011001000100110010000101
　　1001100010100010000100000101111111111100
　　1001011010101100001000000011000110110000
　　0011000100011000010111101000101110110001
"""
"""
mydict = {
    1: '0000100010000001101010101001001100000011',
    2: '0101111001111101110111100000101010011111',
    3: '1000010000011101010110000000001011010100',
    4: '0110101010110000000101100100000101001001',
    5: '0000011010100000111111001101100010101001',
    6: '0110000110000000110100000000010010100011',
    7: '0100110010000110000000100010000101110000',
    8: '0010011010100110001111001101100110100010',
    9: '1111000111101000001110010001001011101101',
    10: '0011110100011000000001101001101110100001',
    11: '0000000101011000010011111001010011011100',
    12: '0000100000011001000100101000111011101100',
    13: '0010110000001000001010100011000010100011',
    14: '0110110000100011011010011010001101011011',
    15: '0000100100000001010000101100000000000010',
    16: '0011001000001000000010011001100101000110',
    17: '1110101000011000000100011001001100111010',
    18: '0000100100111000001101001000001010010001',
    19: '0100010010000110100001100000110111110101',
    20: '1000001001100010011001111101011001110001',
    21: '0000000010100101000000111100110010101101',
    22: '0010110101001100000100000010000010110011',
    23: '0000011101001001000111011000100111010100',
    24: '0010001100100000011000101011000000010101',
    25: '1001111010010110011010101110000000101110',
    26: '0110011101000010100001000101001001100010',
    27: '1101000000010010011001000100110010000101',
    28: '1001100010100010000100000101111111111100',
    29: '1001011010101100001000000011000110110000',
    30: '0011000100011000010111101000101110110001',
}
mydict1 = {}
for a in range(1,31):
    mydict2 = {}
    for b in range(1,41):
        mydict1[a] = mydict2[b]
        for c in mydict[a]:
            mydict2[b] = c

print(mydict1)
"""
"""
list1 = [1,2,3]
list2 = [4,5,6]
print(list1 + list2)

s = 'rocky'
print(s[-3])

a = [1,2,3]
for i in a[::-1]:
    print(i,end=",")

s = []
print(type(s))

print('---------------')
t = ('cat','dog','tiger','human')
for i in t[::-1]:
    print(i,end=",")
"""
"""
import re


def extract_frequent_words(text, threshold=6):
    # 使用正则表达式提取单词（忽略大小写）
    words = re.findall(r'\b\w+\b', text.lower())

    # 创建一个字典来统计每个单词的出现次数
    word_counts = {}

    # 统计每个单词的出现次数
    for word in words:
        if word in word_counts:
            word_counts[word] += 1
        else:
            word_counts[word] = 1

    # 提取出现次数大于等于阈值的单词
    frequent_words = {word: count for word, count in word_counts.items() if count >= threshold}

    return frequent_words


# 测试文本
text = '''
Python is an easy to learn, powerful programming language. It has efficient high-level data structures 
and a simple but effective approach to object-oriented programming. Python’s elegant syntax and dynamic 
typing, together with its interpreted nature, make it an ideal language for scripting and rapid application 
development in many areas on most platforms.Python is an easy to learn, powerful programming language. It has efficient high-level data structures 
and a simple but effective approach to object-oriented programming. Python’s elegant syntax and dynamic 
typing, together with its interpreted nature, make it an ideal language for scripting and rapid application 
development in many areas on most platforms.Python is an easy to learn, powerful programming language. It has efficient high-level data structures 
and a simple but effective approach to object-oriented programming. Python’s elegant syntax and dynamic 
typing, together with its interpreted nature, make it an ideal language for scripting and rapid application 
development in many areas on most platforms.Python is an easy to learn, powerful programming language. It has efficient high-level data structures 
and a simple but effective approach to object-oriented programming. Python’s elegant syntax and dynamic 
typing, together with its interpreted nature, make it an ideal language for scripting and rapid application 
development in many areas on most platforms.Python is an easy to learn, powerful programming language. It has efficient high-level data structures 
and a simple but effective approach to object-oriented programming. Python’s elegant syntax and dynamic 
typing, together with its interpreted nature, make it an ideal language for scripting and rapid application 
development in many areas on most platforms.
'''

# 提取出现6次及以上的单词
frequent_words = extract_frequent_words(text, threshold=6)
print(frequent_words)

"""


def count_twos(matrix):
    # 行数和列数
    rows = len(matrix)
    cols = len(matrix[0])

    # 四个方向：上、下、左、右
    directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]

    # 创建一个列表来模拟队列，用于BFS，初始位置为(0, 0)
    queue = [(0, 0)]

    # 将起始位置的0变为2
    if matrix[0][0] == '0':
        matrix[0][0] = '2'

    # BFS遍历
    while queue:
        x, y = queue.pop(0)  # 取出队列的第一个元素

        # 遍历四个方向
        for dx, dy in directions:
            nx, ny = x + dx, y + dy

            # 检查新的坐标是否在矩阵范围内，并且该位置是0
            if 0 <= nx < rows and 0 <= ny < cols and matrix[nx][ny] == '0':
                # 将该位置变为2，并将其加入队列
                matrix[nx][ny] = '2'
                queue.append((nx, ny))

    # 统计矩阵中2的数量
    count = sum(row.count('2') for row in matrix)

    return count


# 输入矩阵
matrix = [
    list("0000100010000001101010101001001100000011"),
    list("0101111001111101110111100000101010011111"),
    list("1000010000011101010110000000001011010100"),
    list("0110101010110000000101100100000101001001"),
    list("0000011010100000111111001101100010101001"),
    list("0110000110000000110100000000010010100011"),
    list("0100110010000110000000100010000101110000"),
    list("0010011010100110001111001101100110100010"),
    list("1111000111101000001110010001001011101101"),
    list("0011110100011000000001101001101110100001"),
    list("0000000101011000010011111001010011011100"),
    list("0000100000011001000100101000111011101100"),
    list("0010110000001000001010100011000010100011"),
    list("0110110000100011011010011010001101011011"),
    list("0000100100000001010000101100000000000010"),
    list("0011001000001000000010011001100101000110"),
    list("1110101000011000000100011001001100111010"),
    list("0000100100111000001101001000001010010001"),
    list("0100010010000110100001100000110111110101"),
    list("1000001001100010011001111101011001110001"),
    list("0000000010100101000000111100110010101101"),
    list("0010110101001100000100000010000010110011"),
    list("0000011101001001000111011000100111010100"),
    list("0010001100100000011000101011000000010101"),
    list("1001111010010110011010101110000000101110"),
    list("0110011101000010100001000101001001100010"),
    list("1101000000010010011001000100110010000101"),
    list("1001100010100010000100000101111111111100"),
    list("1001011010101100001000000011000110110000"),
    list("0011000100011000010111101000101110110001")
]

# 计算矩阵中有多少个2
result = count_twos(matrix)
print(result)
